function convert_str(bingo)
	if (string.len(bingo) % 2 ~= 0) then
		return nil
	end

	local target = ""
	for i=1, string.len(bingo) do
		if (i % 2 == 0) then
			target = target .. string.sub(bingo, i, i)
		end

	end
	return target
end

function play_query_lxy(playId, butType, zlStr,djStr)
	if zlStr == nil or djStr == nil then
		return 0
	end
	if playId == '1' then --双色球
		require "ssq"
		return query_ssq(butType,zlStr, djStr)
	elseif playId == '2' then --七乐彩
		require "qlc"
		return query_qlc(butType,zlStr, djStr)
	elseif playId == '3' then --3D
		require "3d"
		djStr = convert_str(djStr)
		return query_3d(butType,zlStr, djStr)
	elseif playId == '4' then --天天彩4
		return 0
	elseif playId == '5' then --15选5
		return 0
	elseif playId == '6' then --东方6+1
		return 0
	elseif playId == '7' then --时时彩
		require "ssc"
		--djStr = convert_str(djStr)
		return query_ssc(butType,zlStr, djStr)
	elseif playId == '8' then --35选7
		return 0
	elseif playId == '9' then --18选7
		return 0
	elseif playId == '0' then --10选7
		return 0
	elseif playId == 'a' then --25选7
		return 0
	elseif playId == 'b' then --15选7
		return 0
	elseif playId == 'c' then --快乐10
		require "kl10"
		return query_kl10(butType,zlStr, djStr)
	elseif playId == 'd' then --快乐10
		require "pk3"
		return query_pk3(butType,zlStr, djStr)
	elseif playId == 'e' then --大乐透
		require "dlt"
		return query_dlt(butType,zlStr, djStr)
	elseif playId == 'f' then --12生肖
		require "122"
		return query_122(butType,zlStr, djStr)
	elseif playId == 'g' then --七星彩
		require "qxc"
		djStr = convert_str(djStr)
		return query_qxc(butType,zlStr, djStr)
	elseif playId == 'h' then --排列三
		require "pl3"
		djStr = convert_str(djStr)
		return query_pl3(butType,zlStr, djStr)
	elseif playId == 'i' then --排列五
		require "pl5"
		djStr = convert_str(djStr)
		return query_pl5(butType,zlStr, djStr)
	elseif playId == 'j' then --22选5
		require "225"
		return query_225(butType,zlStr, djStr)
	elseif playId == 'k' then --14场胜负
		require "sf14"
		djStr = convert_str(djStr)
		return query_sf14(butType,zlStr, djStr)
	elseif playId == 'l' then --6场半全场
		require "bq6"
		djStr = convert_str(djStr)
		return query_bq6(butType,zlStr, djStr)
	elseif playId == 'm' then --任选9场
		require "rx9"
		djStr = convert_str(djStr)
		return query_rx9(butType,zlStr, djStr)
	elseif playId == 'n' then --4场进球
		require "j4"
		djStr = convert_str(djStr)
		return query_j4(butType,zlStr, djStr)
	elseif playId == 'o' then --江西11选5
		require "syw"
		return query_syw(butType,zlStr, djStr)
	elseif playId == 'p' then --竞彩
		require "jc"
		return query_jc(playId, butType, zlStr, djStr)
	elseif playId == 'q' then --北京单场
		require "jc"
		return query_jc(playId, butType,zlStr, djStr)
	elseif playId == 'r' then --重庆时时彩
		require "cqssc"
		return query_cqssc(butType,zlStr, djStr)
	elseif playId == 's' then --山东11选5
		require "syw"
		return query_syw(butType,zlStr, djStr)
	elseif playId == 't' then --广西快乐10
		require "gxkl10"
		return query_gxkl10(butType,zlStr, djStr)
	elseif playId == 'u' then --山东群英会
		require "qyh"
		return query_qyh(butType,zlStr, djStr)
	elseif playId == 'v' then --幸运赛车
		require "xysc"
		return query_xysc(butType,zlStr, djStr)
	elseif playId == 'w' then --广东11选5
		require "syw"
		return query_syw(butType,zlStr, djStr)
	elseif playId == 'x' then --快3
		require "k3"
		return query_k3(butType,zlStr, djStr)
	elseif playId == 'y' then --快3
		require "jclq"
		return query_jclq(butType,zlStr, djStr)
	elseif playId == 'z' then --上海11选5
		require "syw"
		return query_syw(butType,zlStr, djStr)
	else
		return 0
	end
end

function play_check(playId, butType, inStr)
	flag, butNum,butPower,butStr,inStr = pcall(play_check_lxy,playId,butType,inStr)
	if flag then
		if butNum ~= 0 then
			return butNum,butPower,butStr,inStr
		else
			return 0
		end
	else
		return 0
	end

end

function play_query(playId, butType, zlStr,djStr)
	flag, result = pcall(play_query_lxy,playId, butType, zlStr,djStr)
	if flag then
		if result ~= nil then
			return result
		else
			return 0
		end
	else
		return 0
	end

end

function play_check_lxy(playId, butType, inStr)
	if inStr == nil then
		return 0
	end
	if playId == '1' then --双色球
		require "ssq"
		return check_ssq(butType, inStr)
	elseif playId == '2' then --七乐彩
		require "qlc"
		return check_qlc(butType, inStr)
	elseif playId == '3' then --3D
		require "3d"
		return check_3d(butType, inStr)
	elseif playId == '4' then --天天彩4
		return 0
	elseif playId == '5' then --15选5
		require "155"
		return check_155(butType, inStr)
	elseif playId == '6' then --东方6+1
		require "df61"
		return check_df61(butType, inStr)
	elseif playId == '7' then --时时彩
		require "ssc"
		return check_ssc(butType, inStr)
	elseif playId == '8' then --35选7
		return 0
	elseif playId == '9' then --18选7
		return 0
	elseif playId == '0' then --10选7
		return 0
	elseif playId == 'a' then --25选7
		return 0
	elseif playId == 'b' then --15选7
		return 0
	elseif playId == 'c' then --快乐10
		require "kl10"
		return check_kl10(butType, inStr)
	elseif playId == 'd' then --快乐10
		require "pk3"
		return check_pk3(butType, inStr)
	elseif playId == 'e' then --大乐透
		require "dlt"
		return check_dlt(butType, inStr)
	elseif playId == 'f' then --12生肖
		require "122"
		return check_122(butType, inStr)
	elseif playId == 'g' then --七星彩
		require "qxc"
		return check_qxc(butType, inStr)
	elseif playId == 'h' then --排列三
		require "pl3"
		return check_pl3(butType, inStr)
	elseif playId == 'i' then --排列五
		require "pl5"
		return check_pl5(butType, inStr)
	elseif playId == 'j' then --22选5
		require "225"
		return check_225(butType, inStr)
	elseif playId == 'k' then --14场胜负
		require "sf14"
		return check_sf14(butType, inStr)
	elseif playId == 'l' then --6场半全场
		require "bq6"
		return check_bq6(butType, inStr)
	elseif playId == 'm' then --任选9场
		require "rx9"
		return check_rx9(butType, inStr)
	elseif playId == 'n' then --4场进球
		require "j4"
		return check_j4(butType, inStr)
	elseif playId == 'o' then --11选5
		require "syw"
		return check_syw(butType, inStr)
	elseif playId == 'p' then --竞彩
		require "jc"
		return check_jc(playId, butType, inStr)
	elseif playId == 'q' then --北京单场
		require "jc"
		return check_jc(playId, butType, inStr)
	elseif playId == 'r' then --重庆时时彩
		require "cqssc"
		return check_cqssc(butType, inStr)
	elseif playId == 's' then --山东11选5
		require "syw"
		return check_syw(butType, inStr)
	elseif playId == 't' then -- 广西快乐10
		require "gxkl10"
		return check_gxkl10(butType, inStr)
	elseif playId == 'u' then -- 广西快乐10
		require "qyh"
		return check_qyh(butType, inStr)
	elseif playId == 'v' then -- 幸运赛车
		require "xysc"
		return check_xysc(butType, inStr)
	elseif playId == 'w' then --广东11选5
		require "syw"
		return check_syw(butType, inStr)
	elseif playId == 'x' then --快3
		require "k3"
		return check_k3(butType, inStr)
	elseif playId == 'y' then --快3
		require "jclq"
		return check_jclq(butType, inStr)
	elseif playId == 'z' then --上海11选5
		require "syw"
		return check_syw(butType, inStr)
	else
		return 0
	end
end


function play_random(playId, butType, inStr)
	flag, butNum, butPower, butStr, zlStr = pcall(play_random_lxy,playId, butType, inStr)
	if flag then
		if butNum ~= 0 then
			return butNum, butPower, butStr, zlStr
		else
			return 0
		end
	else
		return 0
	end

end


function play_random_lxy(playId, butType, inStr)
	if inStr == nil then
		return 0
	end
	if playId == '1' then --双色球
		require "ssq"
		return random_ssq(butType, inStr)
	elseif playId == '2' then --七乐彩
		require "qlc"
		return random_qlc(butType, inStr)
	elseif playId == '3' then --3D
		require "3d"
		return random_3d(butType, inStr)
	elseif playId == '4' then --天天彩4
		return 0
	elseif playId == '5' then --15选5
		require "155"
		return random_155(butType, inStr)
	elseif playId == '6' then --东方6+1
		require "df61"
		return random_df61(butType, inStr)
	elseif playId == '7' then --时时彩
		require "ssc"
		return random_ssc(butType, inStr)
	elseif playId == '8' then --35选7
		return 0
	elseif playId == '9' then --18选7
		return 0
	elseif playId == '0' then --10选7
		return 0
	elseif playId == 'a' then --25选7
		return 0
	elseif playId == 'b' then --15选7
		return 0
	elseif playId == 'c' then --快乐10
		require "kl10"
		return random_kl10(butType, inStr)
	elseif playId == 'e' then --大乐透
		require "dlt"
		return random_dlt(butType, inStr)
	elseif playId == 'f' then --12生肖
		require "122"
		return random_122(butType, inStr)
	elseif playId == 'g' then --七星彩
		require "qxc"
		return random_qxc(butType, inStr)
	elseif playId == 'h' then --排列三
		require "pl3"
		return random_pl3(butType, inStr)
	elseif playId == 'i' then --排列五
		require "pl5"
		return random_pl5(butType, inStr)
	elseif playId == 'j' then --22选5
		require "225"
		return random_225(butType, inStr)
	elseif playId == 'k' then --14场胜负
		require "sf14"
		return random_sf14(butType, inStr)
	elseif playId == 'l' then --6场半全场
		require "bq6"
		return random_bq6(butType, inStr)
	elseif playId == 'm' then --任选9场
		require "rx9"
		return random_rx9(butType, inStr)
	elseif playId == 'n' then --4场进球
		require "j4"
		return random_j4(butType, inStr)
	elseif playId == 'o' then --115
		require "syw"
		return random_syw(butType, inStr)
	elseif playId == 'r' then --重庆时时彩
		require "cqssc"
		return random_cqssc(butType, inStr)
	else
		return 0
	end
end

function play_convert(playId, butType, inStr, iPath)
local cPath = "i01"
	if inStr == nil then
		return 0
	end
	if iPath == nil then
		return 0
	else
		cPath=iPath
	end

	if playId == '1' then --双色球
		require (cPath.."/ssq")
		return convert_ssq(butType, inStr)
	elseif playId == '2' then --七乐彩
		require (cPath.."/qlc")
		return convert_qlc(butType, inStr)
	elseif playId == '3' then --3D
		require (cPath.."/3d")
		return convert_3d(butType, inStr)
	elseif playId == '4' then --天天彩4
		return 0
	elseif playId == '5' then --15选5
		require (cPath.."/155")
		return convert_155(butType, inStr)
	elseif playId == '6' then --东方6+1
		require (cPath.."/df61")
		return convert_df61(butType, inStr)
	elseif playId == '7' then --时时彩
		require (cPath.."/ssc")
		return convert_ssc(butType, inStr)
	elseif playId == '8' then --35选7
		return 0
	elseif playId == '9' then --18选7
		return 0
	elseif playId == '0' then --10选7
		return 0
	elseif playId == 'a' then --25选7
		return 0
	elseif playId == 'b' then --15选7
		return 0
	elseif playId == 'c' then --快乐10
		require (cPath.."/kl10")
		return convert_kl10(butType, inStr)
	elseif playId == 'e' then --大乐透
		require (cPath.."/dlt")
		return convert_dlt(butType, inStr)
	elseif playId == 'f' then --12生肖
		require (cPath.."/122")
		return convert_122(butType, inStr)
	elseif playId == 'g' then --七星彩
		require (cPath.."/qxc")
		return convert_qxc(butType, inStr)
	elseif playId == 'h' then --排列3
		require (cPath.."/pl3")
		return convert_pl3(butType, inStr)
	elseif playId == 'i' then --排列5
		require (cPath.."/pl5")
		return convert_pl5(butType, inStr)
	elseif playId == 'j' then --22选5
		require (cPath.."/225")
		return convert_225(butType, inStr)
	elseif playId == 'k' then --14胜负
		require (cPath.."/sf14")
		return convert_sf14(butType, inStr)
	elseif playId == 'l' then --6场半全场
		require (cPath.."/bq6")
		return convert_bq6(butType, inStr)
	elseif playId == 'm' then --任选9场
		require (cPath.."/rx9")
		return convert_rx9(butType, inStr)
	elseif playId == 'n' then --4场进球
		require (cPath.."/j4")
		return convert_j4(butType, inStr)
	elseif playId == 'r' then --重庆时时彩
		require (cPath.."/cqssc")
		return convert_cqssc(butType, inStr)
	else
		return 0
	end
end

--test
--print(play_check('d','1',"05"))
--print(play_random('o','f',"1"))
--print(play_check('p','4',"140321002=1:0/2:0/2:1/3:0/3:1/3:2/4:0/4:1/4:2/5:0/5:1/5:2/9:0/0:0/1:1/2:2/3:3/9:9/0:1/0:2/1:2/0:3/1:3/2:3/0:4/1:4/2:4/0:5/1:5/2:5/0:9,140321003=1:0/2:0/2:1/3:0/3:1/3:2/4:0/4:1/4:2/5:0/5:1/5:2/9:0/0:0/1:1/2:2/3:3/9:9/0:1/0:2/1:2/0:3/1:3/2:3/0:4/1:4/2:4/0:5/1:5/2:5/0:9|2*1"))
--print(play_check('o','b',"010203"))
--print(play_check('2','1',"01020304050607#33040501030806"))
--print(play_check('2','2',"33020304050607#12"))
--print(play_check('2','3',"3332313019020304050607#2"))
--print(play_check('2','4',"33323130*19020304050607"))
--print(play_query('h','6',"9","441"))
--print(play_query('e','3',"0102030405#06#0107#B5","0102030405|0607"))
--print(play_query('j','3',"01020306#050708#B5","0102030405"))
--print(play_query('j','3',"01020306#050708#B5","0102030405"))
--print(play_query('g','2',"8#3#7#0#1#3#0#B99","08070406080304"))
--print(play_query('k','2',"012#0#345612#0#0#0#0#0#0#0#0#0#0#0#B5","00000000000000"))

--print(play_query('p','2',"30#*#3#*#31#*#3#3#*#0#31#*#3#3#B1","000003000101030001000*030303"))
--print(play_query('m','2',"12#*#*#0#*#0#0#0#0#0#0#*#*#0#B5","00000000000000"))
--print(play_query('l','2',"012#0#0#0#0#0#0#0#0#0#0#0#B5","000000000000"))
--print(play_query('l','1',"000000000000#000000000000#B5","000000000000"))
--print(play_query('n','1',"00000003#00000000#B5","00000000"))
--print(play_query('n','2',"012#031#0#0#0#0#0#0#B5","00000000"))
--print(play_check('3','6',"#778"))
--print(play_query('h','4',"012369#B1","000102"))
--print(play_query('o','p',"01#0203040506070809","0102030405"))
--print("1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5")
--print(play_query('g','2',"24680#24680#13579#13579#13579#13579#13579","02040101010101"))
--print(play_query('k','1',"03331300333103#B1","010301030101030303000"))
--print(play_query('i','2',"1#23#3#4#5","0102030405"))
--print(play_query('7','9',"0102030405#2","0102030405"))
--print(play_query('7','e',"01*02*03*04*0105","0102030405"))
--print(play_query('7','5',"0102030401","0102030401"))
--print(play_query('7','d',"0203*03*01*0304#2","0102030105"))
--print(play_query('7','5',"0102030403**0102030404#2","0102030405"))
--print(play_query('7','5',"0102030405**0102030404#2","0102030405"))
--print(play_query('7','e',"0102*02*0304*0405*05#2","0102030405"))
--print(play_query('7','e',"0102*03*0304*0405*05#2","0102030405"))
--print(play_query('7','6',"0405#2","0102030405"))
--print(play_query('7','6',"0305#2","0102030405"))
--print(play_query('7','6',"0304#2","0102030405"))
--print(play_query('7','7',"030405#2","0102030405"))
--print(play_query('7','7',"020304#2","0102030405"))
--print(play_query('7','8',"02030405#2","0102030405"))
--print(play_query('7','9',"0101010101#2","0102030405"))
--print(play_query('7','f',"15#2","0102040405"))
--print(play_query('7','h',"0304**0304#2","0102030304"))
--print(play_query('7','h',"020204**020404#2","0102020404"))
--print(play_query('7','h',"020204**020405#2","0102020404"))
--print(play_query('7','g',"0102030405#2","0102030405"))
--print(play_query('7','g',"0202030405#2","0102030405"))
--print(play_query('7','g',"0102030402#2","0102030405"))
--print(play_query('7','g',"0102020405#2","0102030405"))
--print(play_query('7','g',"0202020402#2","0102030405"))
--print(play_query('7','i',"0102030405#2","0102030405"))
--print(play_query('7','i',"0102030405#2","0102030404"))
--print(play_query('7','i',"0102030405#2","0102030506"))
--print(play_query('7','j',"0102030405#2","0102040405"))
--print(play_query('7','j',"0102030405#2","0102060605"))
--print(play_query('7','k',"0702060405#2","0102060705"))
--print(play_query('7','k',"0702060405#2","0102060708"))
--print(play_query('7','l',"15#2","0102060708"))
--print(play_query('7','l',"14#2","0102060707"))
--print(play_query('7','l',"14#2","0102060708"))
--print(play_query('7','t',"0108#2","0102060708"))
--print(play_query('7','t',"0207#2","0102060708"))
--print(play_query('7','t',"0406#2","0102060708"))
--print(play_query('7','t',"0802#2","0102060708"))
--print(play_query('7','t',"1601#2","0102060708"))
--print(play_query('7','u',"030708#2","0102060708"))
--print(play_query('7','u',"050608#2","0102060708"))
--print(play_query('7','u',"060607#2","0102060708"))
--print(play_query('7','u',"090208#2","0102060708"))
--print(play_query('7','u',"100207#2","0102060708"))
--print(play_query('7','u',"120206#2","0102060708"))
--print(play_query('7','u',"170108#2","0102060708"))
--print(play_query('7','u',"180107#2","0102060708"))
--print(play_query('7','u',"200106#2","0102060708"))
--print(play_query('7','u',"240102#2","0102060708"))
--print(play_query('z','2',"0405#B2","0102030405"))
--print(play_query('s','2',"0305#B2","0102030405"))
--print(play_query('s','3',"030405#B2","0102030405"))
--print(play_query('s','3',"010305#B2","0102030405"))
--print(play_query('s','5',"0304#0506#B2","0102030405"))
--print(play_query('s','5',"0304#0506#B2","0102030407"))
--print(play_query('s','6',"03#0204#0506#B2","0102030405"))
--print(play_query('s','6',"02#0304#0506#B2","0102030407"))
--print(play_query('s','7',"02030407#B2","0102030407"))
--print(play_query('s','7',"02030408#B2","0102030407"))
--print(play_query('s','8',"02030407#B2","0102030407"))
--print(play_query('s','8',"02030408#B2","0102030407"))
--print(play_query('s','9',"04#030507#B2","0102030407"))
--print(play_query('s','9',"02#030408#B2","0102030407"))
--print(play_query('s','a',"04#030507#B2","0102030407"))
--print(play_query('s','a',"02#030408#B2","0102030407"))
--print(play_query('s','b',"02030408#B2","0102030407"))
--print(play_query('s','b',"0809#B2","0102030407"))
--print(play_query('s','c',"02030408#B2","0102030407"))
--print(play_query('s','c',"070809#B2","0102030407"))
--print(play_query('s','d',"02030408#B2","0102030407"))
--print(play_query('s','d',"070809#B2","0102030407"))
--print(play_query('s','e',"01070203040809#B2","0102030407"))
--print(play_query('s','e',"0506070809#B2","0102030407"))
--print(play_query('s','f',"01070203040809#B2","0102030407"))
--print(play_query('s','f',"0506070809#B2","0102030407"))
--print(play_query('s','g',"010203040506070809#B2","0102030405"))
--print(play_query('s','g',"01020506070809#B2","0102030407"))
--print(play_query('s','h',"010203040506070809#B2","0102030405"))
--print(play_query('s','h',"01020506070809#B2","0102030407"))
--print(play_query('s','i',"010203040506070809#B2","0102030405"))
--print(play_query('s','i',"0102030506070809#B2","0102030407"))
--print(play_query('s','j',"01#0203040506070809#B2","0102030405"))
--print(play_query('s','j',"05#01030506070809#B2","0102030407"))
--print(play_query('s','k',"01#0203040506070809#B2","0102030405"))
--print(play_query('s','k',"06#01030506070809#B2","0102030405"))
--print(play_query('s','l',"01#0203040506070809#B2","0102030405"))
--print(play_query('s','l',"06#01030506070809#B2","0102030405"))
--print(play_query('s','m',"01#0203040506070809#B2","0102030405"))
--print(play_query('s','m',"06#01030506070809#B2","0102030405"))
--print(play_query('s','n',"01#0203040506070809#B2","0102030405"))
--print(play_query('s','n',"06#01020304050708#B2","0102030405"))
--print(play_query('s','o',"01#0203040506070809#B2","0102030405"))
--print(play_query('s','o',"1101#1002030405070809#B2","0102030405"))
--print(play_query('s','p',"0102#03040506070809#B2","0102030405"))
--print(play_query('s','p',"06#0102030405070809#B2","0102030405"))
--print(play_query('s','p',"01#0203040506070809#B2","0102030405"))
--print(play_query('s','p',"1001#0203040506070809#B2","0102030405"))
--print(play_query('t','0',"05#B2","0102030405"))
--print(play_random('o','8',"1#B1"))
